home *** CD-ROM | disk | FTP | other *** search
- /**************************
- Transition.c
- created by Kirk Chase 3/29/90
- ***************************/
- #include "Transition.h"
- /* external variables and globals */
- extern pascal RgnHandle MakeRgn(BitMap *srcMap); /* in 32 bit QD */
-
- /************************************/
- /* routines:
- • Ptr NewBitMap(bm, r)
- • void DisposBitMap(bm)
- • GrafPtr NewOffScreen(theBounds)
- • void DisposOffScreen(offPort)
- • void WipeTopBottom(srcBits, dstBits, srcRect, dstRect, mode, mask,
- partitions, pauseTicks)
- • void WipeBottomTop(srcBits, dstBits, srcRect, dstRect, mode, mask,
- partitions, pauseTicks)
- • void WipeLeftRight(srcBits, dstBits, srcRect, dstRect, mode, mask,
- partitions, pauseTicks)
- • void WipeRightLeft(srcBits, dstBits, srcRect, dstRect, mode, mask,
- partitions, pauseTicks)
- • void Iris(srcBits, dstBits, srcRect, dstRect, mode, mask,
- irisRgn, pauseTicks)
- • void FadePat(srcBits, dstBits, srcRect, dstRect, mode, mask,
- patList, patCount, pauseTicks)
- • void PageFlipDown(srcBits, dstBits, srcRect, dstRect, mask,
- partitions, pauseTicks)
- • void PageFlipRight(srcBits, dstBits, srcRect, dstRect, mask,
- partitions, pauseTicks)
- */
- /************************************/
-
- /************************************/
- /* Ptr NewBitMap()
- creates a bitmap */
- /************************************/
- Ptr NewBitMap(bm, r)
- BitMap *bm;
- Rect *r;
- { /* NewBitMap() */
- bm->rowBytes = ((r->right - r->left + 15) / 16) * 2;
- bm->bounds = *r;
- bm->baseAddr = NewPtr(bm->rowBytes * (long) (r->right - r->left));
- if (MemError() != noErr) return (0L);
- else return (bm->baseAddr);
- } /* NewBitMap() */
-
- /************************************/
- /* void DisposBitMap()
- disposes of a bitmap */
- /************************************/
- void DisposBitMap(bm)
- BitMap *bm;
- { /* DisposBitMap() */
- DisposPtr(bm->baseAddr);
- SetRect(&bm->bounds,0,0,0,0);
- bm->rowBytes=0;
- bm->baseAddr=0L;
- } /* DisposBitMap() */
-
- /************************************/
- /* GrafPtr NewOffScreen()
- creates an offscreen grafport */
- /************************************/
- GrafPtr NewOffScreen(theBounds)
- Rect *theBounds;
- { /* NewOffScreen() */
- GrafPtr oldPort, offPort;
-
- /* allocate port memory */
- offPort = (GrafPtr) NewPtr(sizeof(GrafPort));
- if (MemError() != noErr)
- return (0L);
-
- /* open port and set port variables */
- GetPort(&oldPort);
- OpenPort(offPort);
- offPort->portRect = *theBounds;
-
- if (NewBitMap(&(offPort->portBits), theBounds) == (0L)) {
- ClosePort(offPort);
- SetPort(oldPort);
- DisposPtr((Ptr) offPort);
- return(0L);
- }
-
- RectRgn(offPort->clipRgn, theBounds);
- RectRgn(offPort->visRgn, theBounds);
-
- EraseRect(theBounds);
-
- SetPort(oldPort);
-
- return(offPort);
-
-
- } /* NewOffScreen() */
-
- /************************************/
- /* void DisposOffScreen()
- destroys an offscreen grafport */
- /************************************/
- void DisposOffScreen(offPort)
- GrafPtr offPort;
- { /* DisposOffScreen() */
- ClosePort(offPort);
- DisposBitMap(&(offPort->portBits));
- DisposPtr((Ptr) offPort);
- } /* DisposOffScreen() */
-
- /************************************/
- /* void WipeTopBottom()
- WipeTopBottom uses CopyBits to transfer one image on top of another
- in segments called partitions with an optional pause */
- /************************************/
- void WipeTopBottom(srcBits, dstBits, srcRect, dstRect, mode, mask,
- partitions, pauseTicks)
- BitMap *srcBits, *dstBits;
- Rect *srcRect, *dstRect;
- int mode;
- RgnHandle mask;
- int partitions;
- long pauseTicks;
- { /*WipeTopBottom */
- int width,i, j;
- Rect partSRect, partDRect;
- long ticks;
-
- width = (srcRect->bottom - srcRect->top) / partitions;
- while ((partitions * width) < (srcRect->bottom - srcRect->top)) width += 1;
-
- for (j=0; j<width; j++) { /* increment pane */
- ticks = TickCount();
-
- for (i=0; i<partitions; i++) { /* each pane */
- SetRect(&partSRect, srcRect->left,
- (srcRect->top) + (i * width) + j,
- srcRect->right,
- (srcRect->top) + (i * width) + j + 1);
-
- if (partSRect.bottom > srcRect->bottom) partSRect.bottom = srcRect->bottom;
-
- partDRect = partSRect;
- MapRect(&partDRect, srcRect, dstRect);
-
- CopyBits(srcBits, dstBits, &partSRect, &partDRect, mode, mask);
- } /* each pane */
-
- while (TickCount() < ticks + pauseTicks) ;
- } /* increment pane */
-
- } /*WipeTopBottom */
-
- /************************************/
- /* void WipeBottomTop()
- WipeBottomTop uses CopyBits to transfer one image on top of another
- in segments called partitions with an optional pause */
- /************************************/
- void WipeBottomTop(srcBits, dstBits, srcRect, dstRect, mode, mask,
- partitions, pauseTicks)
- BitMap *srcBits, *dstBits;
- Rect *srcRect, *dstRect;
- int mode;
- RgnHandle mask;
- int partitions;
- long pauseTicks;
- { /*WipeBottomTop */
- int width,i, j;
- Rect partSRect, partDRect;
- long ticks;
-
- width = (srcRect->bottom - srcRect->top) / partitions;
- while ((partitions * width) < (srcRect->bottom - srcRect->top)) width += 1;
-
- for (j=0; j<width; j++) { /* increment pane */
- ticks = TickCount();
-
- for (i=0; i<partitions; i++) { /* each pane */
- SetRect(&partSRect, srcRect->left,
- (srcRect->bottom) - (i * width) - j - 1,
- srcRect->right,
- (srcRect->bottom) - (i * width) - j);
-
- if (partSRect.top < srcRect->top) partSRect.top = srcRect->top;
-
- partDRect = partSRect;
- MapRect(&partDRect, srcRect, dstRect);
-
- CopyBits(srcBits, dstBits, &partSRect, &partDRect, mode, mask);
- } /* each pane */
-
- while (TickCount() < ticks + pauseTicks) ;
- } /* increment pane */
-
- } /*WipeBottomTop */
-
- /************************************/
- /* void WipeLeftRight()
- WipeLeftRight uses CopyBits to transfer one image on top of another
- in segments called partitions with an optional pause */
- /************************************/
- void WipeLeftRight(srcBits, dstBits, srcRect, dstRect, mode, mask,
- partitions, pauseTicks)
- BitMap *srcBits, *dstBits;
- Rect *srcRect, *dstRect;
- int mode;
- RgnHandle mask;
- int partitions;
- long pauseTicks;
- { /*WipeLeftRight */
- int width,i, j;
- Rect partSRect, partDRect;
- long ticks;
-
- width = (srcRect->right - srcRect->left) / partitions;
- while ((partitions * width) < (srcRect->right - srcRect->left)) width += 1;
-
- for (j=0; j<width; j++) { /* increment pane */
- ticks = TickCount();
-
- for (i=0; i<partitions; i++) { /* each pane */
- SetRect(&partSRect, srcRect->left + (i * width) + j,
- srcRect->top,
- srcRect->left + (i * width) + j + 1,
- srcRect->bottom);
-
- if (partSRect.right > srcRect->right) partSRect.right = srcRect->right;
-
- partDRect = partSRect;
- MapRect(&partDRect, srcRect, dstRect);
-
- CopyBits(srcBits, dstBits, &partSRect, &partDRect, mode, mask);
- } /* each pane */
-
- while (TickCount() < ticks + pauseTicks) ;
- } /* increment pane */
-
- } /*WipeLeftRight */
-
- /************************************/
- /* void WipeRightLeft()
- WipeRightLeft uses CopyBits to transfer one image on top of another
- in segments called partitions with an optional pause */
- /************************************/
- void WipeRightLeft(srcBits, dstBits, srcRect, dstRect, mode, mask,
- partitions, pauseTicks)
- BitMap *srcBits, *dstBits;
- Rect *srcRect, *dstRect;
- int mode;
- RgnHandle mask;
- int partitions;
- long pauseTicks;
- { /*WipeRightLeft */
- int width,i, j;
- Rect partSRect, partDRect;
- long ticks;
-
- width = (srcRect->right - srcRect->left) / partitions;
- while ((partitions * width) < (srcRect->right - srcRect->left)) width += 1;
-
- for (j=0; j<width; j++) { /* increment pane */
- ticks = TickCount();
-
- for (i=0; i<partitions; i++) { /* each pane */
- SetRect(&partSRect, srcRect->right - (i * width) - j - 1,
- srcRect->top,
- srcRect->right - (i * width) - j,
- srcRect->bottom);
-
- if (partSRect.left < srcRect->left) partSRect.left = srcRect->left;
-
- partDRect = partSRect;
- MapRect(&partDRect, srcRect, dstRect);
-
- CopyBits(srcBits, dstBits, &partSRect, &partDRect, mode, mask);
- } /* each pane */
-
- while (TickCount() < ticks + pauseTicks);
- } /* increment pane */
-
- } /*WipeRightLeft */
-
- /************************************/
- /* void Iris()
- Iris uses CopyBits to transfer one image on top of another
- using an iris region with an optional pause */
- /************************************/
- void Iris(srcBits, dstBits, srcRect, dstRect, mode, mask,
- irisRgn, pauseTicks)
- BitMap *srcBits, *dstBits;
- Rect *srcRect, *dstRect;
- int mode;
- RgnHandle mask;
- long pauseTicks;
- RgnHandle irisRgn;
- { /* Iris() */
- long ticks;
- RgnHandle theMask, sumRgn;
- RgnHandle iris;
-
- /* prepare iris */
- iris = NewRgn();
- CopyRgn(irisRgn, iris);
-
- sumRgn = NewRgn();
- SetEmptyRgn(sumRgn);
-
- theMask = NewRgn();
-
- while (!EqualRgn(mask, sumRgn)) {
- SectRgn(iris, mask, theMask);
- ticks = TickCount();
- CopyBits(srcBits, dstBits, srcRect, dstRect, mode, theMask);
- while (TickCount() < ticks + pauseTicks);
-
- /* create new iris region */
- UnionRgn(sumRgn, theMask, sumRgn);
- InsetRgn(iris, -1, -1);
- DiffRgn(iris, sumRgn, iris);
- } /* while */
-
- DisposeRgn(sumRgn);
- DisposeRgn(iris);
- DisposeRgn(theMask);
- } /* Iris() */
-
- /************************************/
- /* void FadePat()
- FadePat uses CopyBits to transfer one image on top of another
- using a series of patterns with an optional pause */
- /************************************/
- void FadePat(srcBits, dstBits, srcRect, dstRect, mode, mask,
- patList, patCount, pauseTicks)
- BitMap *srcBits, *dstBits;
- Rect *srcRect, *dstRect;
- int mode;
- RgnHandle mask;
- long pauseTicks;
- int patList;
- int patCount;
- { /* FadePat() */
- int i;
- long ticks;
- Pattern pat;
- BitMap bm, *bmPtr;
- Ptr p;
- GrafPort gp, *savePort;
- RgnHandle theRgn;
-
- p = NewBitMap(&bm, srcRect);
- if (p == 0L) return;
-
- bmPtr = (BitMap *) &bm;
-
- GetPort(&savePort);
- OpenPort(&gp);
- SetPortBits(bmPtr);
- RectRgn(gp.clipRgn, &(bmPtr->bounds));
- RectRgn(gp.visRgn, &(bmPtr->bounds));
- gp.portRect = bmPtr->bounds;
-
- for (i=1; i<= patCount; i++) { /* pattern loop */
- GetIndPattern(&pat, patList, i);
- PenPat(pat);
- PaintRect(srcRect);
- theRgn = MakeRgn(bmPtr);
- ticks = TickCount();
- CopyBits(srcBits, bmPtr, srcRect, srcRect, srcCopy, theRgn);
-
- MapRgn(theRgn, srcRect, dstRect);
- CopyBits(bmPtr, dstBits, srcRect, dstRect, mode, theRgn);
- while (TickCount() < ticks + pauseTicks);
- DisposeRgn(theRgn);
- } /* pattern loop */
-
- ClosePort(&gp);
- SetPort(savePort);
-
- DisposBitMap(&bm);
- } /* FadePat() */
-
- /************************************/
- /* void PageFlipDown()
- PageFlipDown uses CopyBits to transfer one image on top of another
- (only in srcCopy Mode) with an optional pause */
- /************************************/
- void PageFlipDown(srcBits, dstBits, srcRect, dstRect, mask,
- partitions, pauseTicks)
- BitMap *srcBits, *dstBits;
- Rect *srcRect, *dstRect;
- RgnHandle mask;
- int partitions;
- long pauseTicks;
- { /* PageFlipDown() */
- Rect tempRect = *dstRect;
- char done = 0;
- long ticks;
-
- tempRect.bottom = tempRect.top + partitions;
- if (tempRect.bottom > dstRect->bottom) tempRect.bottom = dstRect->bottom;
- while (!done) {
- ticks = TickCount();
- CopyBits(srcBits, dstBits, srcRect, &tempRect, srcCopy, mask);
- while (TickCount() < ticks + pauseTicks);
-
- if (tempRect.bottom == dstRect->bottom) done = 1;
- tempRect.bottom = tempRect.bottom + partitions;
- if (tempRect.bottom > dstRect->bottom) tempRect.bottom = dstRect->bottom;
- }
- } /* PageFlipDown() */
-
- /************************************/
- /* void PageFlipRight()
- PageFlipRight uses CopyBits to transfer one image on top of another
- (only in srcCopy Mode) with an optional pause */
- /************************************/
- void PageFlipRight(srcBits, dstBits, srcRect, dstRect, mask,
- partitions, pauseTicks)
- BitMap *srcBits, *dstBits;
- Rect *srcRect, *dstRect;
- RgnHandle mask;
- int partitions;
- long pauseTicks;
- { /* PageFlipRight() */
- Rect tempRect = *dstRect;
- char done = 0;
- long ticks;
-
- tempRect.right = tempRect.left + partitions;
- if (tempRect.right > dstRect->right) tempRect.right = dstRect->right;
- while (!done) {
- ticks = TickCount();
- CopyBits(srcBits, dstBits, srcRect, &tempRect, srcCopy, mask);
- while (TickCount() < ticks + pauseTicks);
-
- if (tempRect.right == dstRect->right) done = 1;
- tempRect.right = tempRect.right + partitions;
- if (tempRect.right > dstRect->right) tempRect.right = dstRect->right;
- }
- } /* PageFlipRight() */